# coding:utf-8
from odoo import models, fields, api, _
from odoo.exceptions import Warning
from datetime import datetime, timedelta


class PaulSaleOrderExtend(models.Model):
    _name = 'sale.order'
    _inherit = ["sale.order"]

    customer_payment_term_ids = fields.Many2many('account.payment.term', related='partner_id.customer_payment_term_ids',
                                                 readonly=True)
    property_product_pricelist_ids = fields.Many2many('product.pricelist',
                                                      related='partner_id.property_product_pricelist_ids',
                                                      readonly=True)


    @api.onchange('partner_id')
    def _onchange_partner_id(self):
        if self.partner_id:
            self.partner_address = self.partner_id._display_address(without_company=True)
        else:
            self.partner_address = False

        return {
            'domain': {'pricelist_id': [('id', 'in', self.property_product_pricelist_ids.ids)], 'payment_term_id': [('id', 'in', self.customer_payment_term_ids.ids)]},
        }
